package com.clientes;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.eventssmartphone.*;

public class LocalVentaAdapter extends BaseAdapter{

	List<LocalVentaBean> lista;
	Context context;
	LayoutInflater inflater;
	private final ImageDownloader imageDownloader = new ImageDownloader();
	
	public LocalVentaAdapter(List<LocalVentaBean> lista, Context context){
		this.lista = lista;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}
 
	//@Override
	public int getCount() {
		return lista.size();
	}

	//@Override
	public Object getItem(int position) {
		return lista.get(position);
	}

	//@Override
	public long getItemId(int position) {
		return 0;
	}

	//@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if (convertView == null){
			convertView = inflater.inflate(R.layout.cl_itemlocalventa, null);
			
			holder = new ViewHolder();
			holder.nombreLocal= (TextView) convertView.findViewById(R.id.nomLocal);
			holder.dirLocal = (TextView) convertView.findViewById(R.id.dirLocal);
			holder.horarioLocal = (TextView) convertView.findViewById(R.id.horarioLocal);
			holder.imagenLocal = (ImageView) convertView.findViewById(R.id.imgLocal);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		
		LocalVentaBean localVenta = lista.get(position);
		holder.nombreLocal.setText(localVenta.getNombreLocal());
		holder.dirLocal.setText(localVenta.getDireccionLocal());
		holder.horarioLocal.setText(localVenta.getHorarioLocal());
		//imageDownloader.download(localVenta.getUrlImagen(), holder.imagenLocal);
		imageDownloader.download(localVenta.getUrlImagen(), holder.imagenLocal);
		
		return convertView;
	}
	
	class ViewHolder{
		TextView nombreLocal;
		TextView dirLocal;
		TextView horarioLocal;
		ImageView imagenLocal;
	}
	 public ImageDownloader getImageDownloader() {
	        return imageDownloader;
	    }
}
